﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPIS.GERP.GBMS.BLL;

namespace KPIS.GERP.GBMS.APP_UI.Form
{
    public partial class JobSiteDetail : System.Web.UI.Page
    {
        private SystemControlBLL scBLL = new SystemControlBLL();
        private ComboBLL comboBLL = new ComboBLL();
        private SsMng ssMng = new SsMng();

        protected void Page_Load(object sender, EventArgs e)
        {
            var details = new List<Details>(); 

            string jobSiteStrategyID = scBLL.JobSiteStrategyID();

            details.Add(new Details
            {
                ID = "",
                Name = "--- ข้อมูล User คนนี้ ---",
                Detail = ""
            });

            details.Add(new Details
            {
                ID = ssMng.WorkingJobSiteSeq,
                Name = "ID สำนักที่ดำรงอยู่",
                Detail = ""
            });

            details.Add(new Details());
            details.Add(new Details
            {
                ID = "",
                Name = "--- ข้อมูลทั่วไป ---",
                Detail = ""
            });

            details.Add(new Details
                {
                    ID = jobSiteStrategyID,
                    Name = "ID สำนักแผน",
                    Detail = ""
                });


            details.Add(new Details());
            details.Add(new Details
            {
                ID = "",
                Name = "--- หน่วยงานที่เป็นระดับสำนัก ---",
                Detail = ""
            });
            
            var jobSites = comboBLL.ListJobsite();

            foreach (DataRow dr in jobSites.Rows)
            {
                details.Add(new Details
                    {
                        ID = Convert.ToString(dr["value"]),
                        Name = Convert.ToString(dr["text"]),
                        Detail = ""
                    });
            }

            details.Add(new Details());
            details.Add(new Details
            {
                ID = "",
                Name = "--- หน่วยงานทั้งหมด (ที่ใช้งาน)---",
                Detail = ""
            });

            //jobSites = comboBLL.ListJobsiteKPI();

            foreach (DataRow dr in jobSites.Rows)
            {
                string detail;
                string recordStatus = Convert.ToString(dr["record_status"]);
                if (recordStatus == "D")
                    continue;

                switch (recordStatus)
                {
                    case "U":
                        detail = "ใช้งาน";
                        break;
                    case "D":
                        detail = "ถูกลบ";
                        break;
                    default :
                        detail = String.Format("อื่นๆ ({0})", Convert.ToString(dr["record_status"]));
                        break;
                }

                detail += " - ";
                switch (Convert.ToString(dr["job_site_type_seq"]))
                {
                    case "1":
                        detail += "โครงสร้างสถาบัน/กระทรวง";
                        break;
                    case "2":
                        detail += "โครงสร้างบริหารภายใน";
                        break;
                    default:
                        detail += String.Format("อื่นๆ ({0})", Convert.ToString(dr["job_site_type_seq"]));
                        break;
                }


                details.Add(new Details
                {
                    ID = Convert.ToString(dr["value"]),
                    Name = Convert.ToString(dr["text"]),
                    Detail = detail
                });
            }



            details.Add(new Details());
            details.Add(new Details
            {
                ID = "",
                Name = "--- หน่วยงานทั้งหมด (ที่ถูกลบ)---",
                Detail = ""
            });
            
            foreach (DataRow dr in jobSites.Rows)
            { 
                string detail;

                string recordStatus = Convert.ToString(dr["record_status"]);
                if (recordStatus == "U")
                    continue;

                switch (recordStatus)
                {
                    case "U":
                        detail = "ใช้งาน";
                        break;
                    case "D":
                        detail = "ถูกลบ";
                        break;
                    default:
                        detail = String.Format("อื่นๆ ({0})", Convert.ToString(dr["record_status"]));
                        break;
                }

                detail += " - ";
                switch (Convert.ToString(dr["job_site_type_seq"]))
                {
                    case "1":
                        detail += "โครงสร้างสถาบัน/กระทรวง";
                        break;
                    case "2":
                        detail += "โครงสร้างบริหารภายใน";
                        break;
                    default:
                        detail += String.Format("อื่นๆ ({0})", Convert.ToString(dr["job_site_type_seq"]));
                        break;
                }

                
                details.Add(new Details
                {
                    ID = Convert.ToString(dr["value"]),
                    Name = Convert.ToString(dr["text"]),
                    Detail = detail
                });
            }

            RadGrid1.DataSource = details;
            RadGrid1.DataBind();

        }
        
        private class Details
        {
            public string ID { get; set; }
            public string Name { get; set; }
            public string Detail { get; set; }
        }
    }
}